﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="EditDocment.aspx.cs" Inherits="EditDocment" MaintainScrollPositionOnPostback="true" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
    <asp:Panel ID="AuthenticatedHeaderPanel" runat="server">
        <ul id="user">
            <li>
                <asp:LoginStatus ID="LoginStatus1" runat="server" LogoutAction="Redirect" LogoutPageUrl="~/Login.aspx" />
            </li>
        </ul>

        <div id="header-inner">
            <div class="textt">
            <h4>
                <asp:Label runat="server" ID="WelcomeBackMessage"></asp:Label>
                <asp:label id="lblMessage" runat="server" enableviewstate="false" />
            </h4>
            </div>
        </div>
    </asp:Panel>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="Menu" Runat="Server">
<div id="left">
<div id = "navigation">
    <asp:Panel runat="server" ID="AuthenticatedMenuPanel" Width="200px">
        <div id="menu-header">
            <div class="menutext">
                <asp:Label ID="Label1" runat="server" Text="Menu"/>
            </div> 
        </div>
          <asp:Menu ID="Menu1" runat="server" StaticDisplayLevels="3" BackColor="White" DynamicHoverStyle-BorderStyle="NotSet" Width="200px">
              <Items>
                
                <asp:MenuItem Text="Home" Value="Home" navigateurl="Default.aspx">
                  <asp:MenuItem Text="New Document" Value="New Document" navigateurl="AddDocument.aspx">                   
                   </asp:MenuItem>
                </asp:MenuItem>

                <asp:MenuItem Text="Users" Value="My_Users" navigateurl="MyUsers.aspx">
                  <asp:MenuItem Text="New User" Value="New_User" navigateurl="AddUser.aspx">
                   </asp:MenuItem>
                </asp:MenuItem>
               
                <asp:MenuItem Text="Companies" Value="Companies" navigateurl="MyCompanies.aspx">
                  <asp:MenuItem Text="New Company" Value="New_Company" navigateurl="AddCompany.aspx">
                   </asp:MenuItem>
                </asp:MenuItem>
                
                <asp:MenuItem Text="Clients" Value="Clients" navigateurl="MyClients.aspx">
                  <asp:MenuItem Text="New Client" Value="New_Client" navigateurl="AddClient.aspx">
                   </asp:MenuItem>
                </asp:MenuItem>

              </Items>
          </asp:Menu>
     </asp:Panel>
    </div>
</div>
</asp:Content>
        
<asp:Content ID="Content3" runat="server" contentplaceholderid="MainContent">
   <div id= "right"> 
    <asp:Panel runat="server" ID="AuthenticatedMessagePanel">
        <div class="box">
            <div class ="title">
                <h6>
                    <asp:Label ID="Label3" runat="server" Text="Edit document"></asp:Label>
                </h6>
            </div>
        <div class="lists">
            <table id="tab">
                <tbody>
                    <tr>
                        <th class="text">User:</th>
                        <td colspan="3">
                            <asp:Label ID="lbl_user_id" runat="server" Text=" " Visible="false"></asp:Label>
                            <asp:Label ID="lbl_doc_id" runat="server" Text=" " Visible="false"></asp:Label>
                            <asp:Label ID="lbl_user" runat="server" Text=" "></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <th class="text">Document type:</th>
                        <td colspan="3">
                            <asp:DropDownList ID="Drop_doc_type" runat="server" AutoPostBack="True" onselectedindexchanged="Drop_doc_type_SelectedIndexChanged"></asp:DropDownList>
                            <asp:RequiredFieldValidator ID="doc_type_Validator" runat="server" ControlToValidate="Drop_doc_type" ErrorMessage="<div>Document type cannot be blank.</div>" SetFocusOnError="true" Display="Dynamic" ValidationGroup="edit" InitialValue="--Select--"></asp:RequiredFieldValidator>
                        </td>
                    </tr>

                    <tr>
                        <th class="text">Document number:</th>
                        <td colspan="3">
                            <asp:TextBox Enabled="False" BorderStyle="None" BackColor="#FFFFFF" Font-Bold="True" ID="tb_doc_number" runat="server"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="doc_number_Validator" runat="server" ControlToValidate="tb_doc_number" ErrorMessage="<div>Document number cannot be blank.</div>" SetFocusOnError="true" Display="Dynamic" ValidationGroup="edit"></asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr>
                        <th class="text">Document date:</th>
                        <td colspan="3">
                            <asp:TextBox ID="tb_doc_date" runat="server"></asp:TextBox>
                            <asp:Image ID="Image1" runat="server" ImageUrl="Images/date_picker.png" />
                            <ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="tb_doc_date" PopupButtonID="Image1" Format="yyyy.MM.dd"></ajaxToolkit:CalendarExtender>
                            <asp:RequiredFieldValidator ID="doc_date_Validator" runat="server" ControlToValidate="tb_doc_date" ErrorMessage="<div>Document date cannot be blank.</div>" SetFocusOnError="true" Display="Dynamic" ValidationGroup="edit"></asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr>
                        <th class="text">Document payment date:</th>
                        <td colspan="3">
                            <asp:TextBox ID="tb_doc_pay_date" runat="server"></asp:TextBox>
                            <asp:Image ID="Image2" runat="server" ImageUrl="Images/date_picker.png" />
                            <ajaxToolkit:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="tb_doc_pay_date" PopupButtonID="Image2" Format="yyyy.MM.dd"></ajaxToolkit:CalendarExtender>
                            <asp:RequiredFieldValidator ID="doc_pay_date_Validator" runat="server" ControlToValidate="tb_doc_pay_date" ErrorMessage="<div>Document payment date cannot be blank.</div>" SetFocusOnError="true" Display="Dynamic" ValidationGroup="edit"></asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr>
                        <th class="text">Company from:</th>
                        <td colspan="3">
                            <asp:DropDownList ID="Drop_company_from" runat="server" AutoPostBack="True" onselectedindexchanged="Drop_company_from_SelectedIndexChanged"></asp:DropDownList>
                            <asp:RequiredFieldValidator ID="company_from_Validator" runat="server" ControlToValidate="Drop_company_from" ErrorMessage="<div>Company cannot be blank.</div>" SetFocusOnError="true" Display="Dynamic" ValidationGroup="edit" InitialValue="--Select--"></asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr>
                        <td rowspan="3"  class="text"></td>
                        <th class="text">Company address:</th>
                        <td colspan="2">
                            <asp:DropDownList ID="Drop_address_company_from" runat="server" ></asp:DropDownList>
                            <asp:RequiredFieldValidator ID="Drop_address_company_from_Validator" runat="server" ControlToValidate="Drop_ADDRESS_company_from" ErrorMessage="<div>Company address cannot be blank.</div>" SetFocusOnError="true" Display="Dynamic" ValidationGroup="edit" InitialValue="--Select--"></asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr>
                        <th rowspan="2" class="text">Bank & Account nr.:</th>
                        <th class="text">Bank:</th>
                            <td>
                                <asp:DropDownList ID="Drop_BANK_company_from" runat="server" AutoPostBack="True" onselectedindexchanged="Drop_BANK_company_from_SelectedIndexChanged"></asp:DropDownList>
                                <asp:RequiredFieldValidator ID="Drop_BANK_company_from_Validator" runat="server" ControlToValidate="Drop_BANK_company_from" ErrorMessage="<div>Company bank cannot be blank.</div>" SetFocusOnError="true" Display="Dynamic" ValidationGroup="edit" InitialValue="--Select--"></asp:RequiredFieldValidator>
                            </td>
                    </tr>
                    <tr>
                         <th class="text">Account: </th>
                            <td>
                                <asp:DropDownList ID="Drop_ACCOUNT_company_from" runat="server"></asp:DropDownList>
                                <asp:RequiredFieldValidator ID="Drop_account_company_from_Validator" runat="server" ControlToValidate="Drop_ACCOUNT_company_from" ErrorMessage="<div>Bank account cannot be blank.</div>" SetFocusOnError="true" Display="Dynamic" ValidationGroup="edit" InitialValue="--Select--"></asp:RequiredFieldValidator>
                            </td>
                    </tr>
                    <tr>
                        <th class="text">Client to:</th>
                        <td colspan="3">
                            <asp:DropDownList ID="Drop_client_to" runat="server" AutoPostBack="True" onselectedindexchanged="Drop_client_to_SelectedIndexChanged"></asp:DropDownList>
                            <asp:RequiredFieldValidator ID="client_to_Validator" runat="server" ControlToValidate="Drop_client_to" ErrorMessage="<div>Client cannot be blank.</div>" SetFocusOnError="true" Display="Dynamic" ValidationGroup="edit" InitialValue="--Select--"></asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr>
                        <th rowspan="3" class="text" >
                        <th class="text">Client address:</th>
                        <td colspan="2">
                            <asp:DropDownList ID="Drop_address_client_to" runat="server"></asp:DropDownList>
                            <asp:RequiredFieldValidator ID="address_client_to_Validator" runat="server" ControlToValidate="Drop_ADDRESS_client_to" ErrorMessage="<div>Client address cannot be blank.</div>" SetFocusOnError="true" Display="Dynamic" ValidationGroup="edit" InitialValue="--Select--"></asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr>
                        <th rowspan="2" class="text">Bank & Account nr.:</th>
                           <th class="text">Bank:</th>
                              <td>
                                  <asp:DropDownList ID="Drop_BANK_client_to" runat="server" AutoPostBack="True" onselectedindexchanged="Drop_BANK_client_to_SelectedIndexChanged1" ></asp:DropDownList>
                                  <asp:RequiredFieldValidator ID="Drop_BANK_client_to_Validator" runat="server" ControlToValidate="Drop_BANK_client_to" ErrorMessage="<div>Client bank cannot be blank.</div>" SetFocusOnError="true" Display="Dynamic" ValidationGroup="edit" InitialValue="--Select--"></asp:RequiredFieldValidator>
                              </td>
                    </tr>
                    <tr>
                           <th class="text">Account: </th>
                              <td>
                                  <asp:DropDownList ID="Drop_ACCOUNT_client_to" runat="server" ></asp:DropDownList>
                                  <asp:RequiredFieldValidator ID="Drop_ACCOUNT_client_to_Validator" runat="server" ControlToValidate="Drop_ACCOUNT_client_to" ErrorMessage="<div>Bank account cannot be blank.</div>" SetFocusOnError="true" Display="Dynamic" ValidationGroup="edit" InitialValue="--Select--"></asp:RequiredFieldValidator>
                              </td>
                    </tr>
                    <tr>
                        <th class="text">Payment type:</th>
                        <td colspan="3">
                            <asp:DropDownList ID="Drop_pay_type" runat="server"></asp:DropDownList>
                            <asp:RequiredFieldValidator ID="pay_type_Validator" runat="server" ControlToValidate="Drop_pay_type" ErrorMessage="<div>Payment type cannot be blank.</div>" SetFocusOnError="true" Display="Dynamic" ValidationGroup="edit" InitialValue="--Select--"></asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr>
                        <th class="text">Place of delivery:</th>
                        <td colspan="3">
                            <asp:TextBox ID="tb_delivery_place" runat="server"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="delivery_place_Validator1" runat="server" ControlToValidate="tb_delivery_place" ErrorMessage="<div>Delivery place cannot be blank.</div>" SetFocusOnError="true" Display="Dynamic" ValidationGroup="edit"></asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr>
                        <th class="buttons"></th>
                        <td colspan="3" class="buttons">
                            <div class="button">
                                <ul id="confirm">
                                    <li>
                                        <asp:LinkButton ID="CancelButton" CommandName="Cancel" runat="server" Text="Cancel" CausesValidation="false" onclick="CancelButton_Click" Width="60px"></asp:LinkButton>
                                    </li>
                                    <li>
                                        <asp:LinkButton ID="EditButton" CommandName="Edit" runat="server" Text="Edit" ValidationGroup="edit" onclick="EditButton_Click" Width="60px"></asp:LinkButton>
                                    </li>
                                </ul>
                            </div>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
     </div>
        <asp:ScriptManager ID="ScriptManager2" runat="server"></asp:ScriptManager>
        <div class="box">
         <div class ="title">
             <h6>
                 <asp:Label ID="Label2" runat="server" Text="Document articles:"/>          
             </h6>
         </div>
         <div class="lists">
         <asp:ListView ID="article_list" runat="server" 
            onitemcommand="article_list_ItemCommand" onitemdatabound="article_list_ItemDataBound" 
            InsertItemPosition="LastItem" 
            onitemediting="article_list_ItemEditing">
             <LayoutTemplate>
                <table id="gradient-style">
                      <thead>
                          <tr>
                            <th> Name</th>
                            <th> Count</th>
                            <th> Price without VAT</th>
                            <th> Sum without VAT</th>
                            <th colspan="6"> Options</th>
                          </tr>
                       </thead>                          
                      <tr ID="itemPlaceholder" runat="server"></tr>                       
                       <tfoot>
                        <tr>
                            <th style="text-align:right" colspan="8">
                            </th>
                        </tr>
                       </tfoot>
                </table>
            </LayoutTemplate>
            <AlternatingItemTemplate>
                <tr>
                    <td id="article_ID" runat="server">
                        <asp:Label ID="id_articleLabel" runat="server" Text='<%# Eval("_id") %>' />
                    </td>
                    <td id="document_ID" runat="server">
                        <asp:Label ID="id_documentLabel" runat="server" Text='<%# Eval("_id_document") %>' />
                    </td>
                    <td>
                        <asp:Label ID="nameLabel" runat="server" Text='<%# Eval("_article_name") %>' />
                    </td>
                    <td>
                        <asp:Label ID="countLabel" runat="server" Text='<%# Eval("_article_count") %>' />
                    </td>
                    <td>
                        <asp:Label ID="priceLabel" runat="server" Text='<%# Eval("_article_price") %>' />
                    </td>
                    <td>
                        <asp:Label ID="sumLabel" runat="server" Text='<%# Eval("_article_sum") %>' />
                    </td>
                    <td>
                        <asp:LinkButton ID="lnkEdit" runat="server" CommandName="Edit">Edit</asp:LinkButton>
                    </td>
                    <td>
                        <asp:LinkButton ID="lnkDelete" runat="server" CommandName="Delete">Delete</asp:LinkButton>
                    </td>
                </tr>
            </AlternatingItemTemplate>
            <ItemTemplate>
                <tr>
                    <td id="article_ID" runat="server">
                        <asp:Label ID="id_articleLabel" runat="server" Text='<%# Eval("_id") %>' />
                    </td>
                    <td id="document_ID" runat="server">
                        <asp:Label ID="id_documentLabel" runat="server" Text='<%# Eval("_id_document") %>' />
                    </td>
                    <td>
                        <asp:Label ID="nameLabel" runat="server" Text='<%# Eval("_article_name") %>' />
                    </td>
                    <td>
                        <asp:Label ID="countLabel" runat="server" Text='<%# Eval("_article_count") %>' />
                    </td>
                    <td>
                        <asp:Label ID="priceLabel" runat="server" Text='<%# Eval("_article_price") %>' />
                    </td>
                    <td>
                        <asp:Label ID="sumLabel" runat="server" Text='<%# Eval("_article_sum") %>' />
                    </td>
                    <td>
                        <asp:LinkButton ID="lnkEdit" runat="server" CommandName="Edit">Edit</asp:LinkButton>
                    </td>
                    <td>
                        <asp:LinkButton ID="lnkDelete" runat="server" CommandName="Delete">Delete</asp:LinkButton>
                    </td>
                </tr>
            </ItemTemplate>
            <EditItemTemplate>
                <td id="article_ID" runat="server">
                    <asp:Label ID="id_articleLabel" runat="server" Text='<%# Eval("_id") %>' />
                </td>
                <td id="document_ID" runat="server">
                    <asp:Label ID="id_documentLabel" runat="server" Text='<%# Eval("_id_document") %>' />
                </td>
                <td>
                    <asp:TextBox ID="tb_name" runat="server" ValidationGroup="edit" Text='<% #Bind("_article_name")%>'></asp:TextBox>
                    <asp:RequiredFieldValidator ID="nameValidator" runat="server" ControlToValidate="tb_name" ErrorMessage="<div>Article name cannot be blank.</div>" SetFocusOnError="true" Display="Dynamic" ValidationGroup="edit_art"></asp:RequiredFieldValidator>
                </td>
                <td>
                    <asp:TextBox ID="tb_count" runat="server" ValidationGroup="edit" Text='<% #Bind("_article_count")%>'></asp:TextBox>
                    <asp:RequiredFieldValidator ID="countValidator" runat="server" ControlToValidate="tb_count" ErrorMessage="<div>Article count cannot be blank.</div>" SetFocusOnError="true" Display="Dynamic" ValidationGroup="edit_art"></asp:RequiredFieldValidator>
                </td>
                <td>
                    <asp:TextBox ID="tb_price" runat="server" ValidationGroup="edit" Text='<% #Bind("_article_price")%>'></asp:TextBox>
                    <asp:RequiredFieldValidator ID="priceValidator" runat="server" ControlToValidate="tb_price" ErrorMessage="<div>Article price cannot be blank.</div>" SetFocusOnError="true" Display="Dynamic" ValidationGroup="edit_art"></asp:RequiredFieldValidator>
                </td>
                <td>
                    <asp:Label ID="lblsum" runat="server" Text='<% #Bind("_article_sum")%>'></asp:Label>
                </td>
                <td>                    
                    <asp:LinkButton ID="lnkUpdate" runat="server" CommandName="Update_article" ValidationGroup="edit_art">Update</asp:LinkButton>
                </td>
                <td>
                    <asp:LinkButton ID="lnkCancel" runat="server" CommandName="Cancel_article">Cancel</asp:LinkButton>                    
                </td>
            </EditItemTemplate>
            <InsertItemTemplate>
            <tr id="Tr1" runat="server">
                <td>
                    <asp:TextBox ID="tb_name_insert" runat="server" ValidationGroup="add" Text='<% #Eval("_article_name")%>'>Name</asp:TextBox>
                    <asp:RequiredFieldValidator ID="nameValidator" runat="server" ControlToValidate="tb_name_insert" ErrorMessage="<div>Article name cannot be blank.</div>" SetFocusOnError="true" Display="Dynamic" ValidationGroup="add"></asp:RequiredFieldValidator>
                </td>
                <td>
                    <asp:TextBox ID="tb_count_insert" runat="server" ValidationGroup="add" Text='<% #Eval("_article_count")%>'>0</asp:TextBox>
                    <asp:RequiredFieldValidator ID="countValidator" runat="server" ControlToValidate="tb_count_insert" ErrorMessage="<div>Article count cannot be blank.</div>" SetFocusOnError="true" Display="Dynamic" ValidationGroup="add"></asp:RequiredFieldValidator>
                </td>
                <td>
                    <asp:TextBox ID="tb_price_insert" runat="server" ValidationGroup="add" Text='<% #Eval("_article_price")%>'>0</asp:TextBox>
                    <asp:RequiredFieldValidator ID="priceValidator" runat="server" ControlToValidate="tb_price_insert" ErrorMessage="<div>Article price cannot be blank.</div>" SetFocusOnError="true" Display="Dynamic" ValidationGroup="add"></asp:RequiredFieldValidator>
                </td>
                <td>
                    <asp:Label ID="lblsum" runat="server" Text='<% #Eval("_article_sum")%>'></asp:Label>
                </td>
                <td colspan="2" style="text-align:center;">
                   <asp:LinkButton ID="lnkInsert" runat="server" CommandName="Insert_article" ValidationGroup="add">Insert</asp:LinkButton>                    
                </td>
            </tr>
            </InsertItemTemplate>
        </asp:ListView>
       </div>
        <div class="button">
            <ul id="Ul1">
                <li>
                    <asp:LinkButton ID="LinkButton1" CommandName="bt_delete_articles" runat="server" Text="Delete articles" ></asp:LinkButton>
                </li>
            </ul>
        </div>
     </div>
   </asp:Panel>
</div>
</asp:Content>